package dmp.frame.java.agent;

import dmp.frame.java.agent.transformer.TransformerManager;
import lombok.extern.slf4j.Slf4j;

import java.lang.instrument.Instrumentation;

/**
 * 处理字节码增强服务
 * 建立web服务器。接收参数从而实时更新
 */
@Slf4j
public class JavaAgent {

    public static Instrumentation inst;

    public static void premain(String agentArgs, Instrumentation inst) {
        JavaAgent.inst = inst;
        TransformerManager.registryTransformer(inst);
        log.info("注册类");
//        Javalin app = Javalin.create(
//                config -> {
//                    config.defaultContentType = "application/json";
//                    config.autogenerateEtags = true;
//                    //静态资源目录config.addStaticFiles("/public");
//                    config.asyncRequestTimeout = 10_000L;
//                    config.enforceSsl = false;
//                }
//        ).start(7000);
//


//        app.get("/jps", ctx -> {
//            inst.addTransformer(new CostTimeTransformer());
//        });
//
//        app.get("/", ctx -> ctx.result("Hello Java Agent!!!"));
//        app.get("/getCostTime", ctx -> ctx.result(JSONObject.toJSONString(CostTimeCollector.getCostTime(), true)));
//        Runtime.getRuntime().addShutdownHook(new Thread(app::stop));




    }
}